define(function (require,exports,module){
	/**--tmpl-require--**/
	require('jtemplate');
	require('jdialog');
	common = require('common');

	exports.init = function(){



        //下架商品
		$("a.js-off").click(function () {

			var data_id = $(this).parents('tr').attr('data-id');
			var url = exports.doOffShelfUrl + '?ids=' + data_id;

			var __confirm = JDialog.win.work({
				title : "下架",
				width : 340,
				height : 180,
				borderWidth : 8,
				lock : true,
				effect : 0,
				content : '<div style="padding-top: 15px;">确定要下架此商品吗？</div>',
				icon : 'warn',
				button : {
					'确认' : function() {
						$.get(url, function(data) {
							__confirm.close();
							if ( data.code == "000" ) {
								layer.alert(data.message, {time: 2000, icon:6});
								setTimeout(function() {location.reload();}, 1000)
							} else {
								layer.alert(data.message, {time: 19000, icon:6});

								//JDialog.tip.work({type:"error", content:data.message, timer:__global.jdialog.timer});
							}
						},"json");
					},
					'取消' : function() {
						__confirm.close();
					}
				}
			});
			return false;

		});
		//上架商品
		$("a.js-on").click(function () {

			var data_id = $(this).parents('tr').attr('data-id');
			var url = exports.doOnShelfUrl + '?ids=' + data_id;

			var __confirm = JDialog.win.work({
				title : "上架",
				width : 340,
				height : 180,
				borderWidth : 8,
				lock : true,
				effect : 0,
				content : '<div style="padding-top: 15px;">确定要上架此商品吗？</div>',
				icon : 'warn',
				button : {
					'确认' : function() {
						$.get(url, function(data) {
							__confirm.close();
							if ( data.code == "0" ) {
								JDialog.tip.work({type:"ok", content:data.message, timer:1000});
								setTimeout(function() {location.reload();}, 1000)
							} else {
								JDialog.tip.work({type:"error", content:data.message, timer:__global.jdialog.timer});
							}
						},"json");
					},
					'取消' : function() {
						__confirm.close();
					}
				}
			});
			return false;

		});


		$(".js-edit").click(function(){
			id = $(this).attr('data-id');
			/**--tmpl-editlayer--**/
			$.get(exports.detailUrl,{id:id},function(data){
		
				var options = {
					type : 1,
					area : ['800px','500px'],
					content : JTemplate.render("editpanel",data),
					btn : {
						'确定' :function(){
							var form = $("#editpanel-form");
							form.validate({
								rules: {

										   /**--tmpl-editrules--**/

									   },
								messages : {  
											   /**--tmpl-editmessages--**/
										   },  

								submitHandler : function(form){

									$(form).find('input[name=id]').remove();
									$(form).append("<input type='hidden' name='id' value='"+id+"' >");
									var data = $(form).serialize();
									common.ajaxResult(exports.editUrl,data);

								}
							});
							form.submit();
						},
						"取消" : function(){
						
						}
					}
				};
				var options = $.extend(__global.jdialog, options);
				var popWin = JDialog.win.work(options);


			},'json');
			
		});
		
		/*旧版批量操作*/
		/*$('select[name=action-bacth-select]').change(function (e) {

			if (!common.hasChecked) return;
			e.stopPropagation();

			var actionName=$(this).children('option:selected').val();

			switch(actionName){

				case 'delete':common.list_bacth_delete();break;
				case 'on':exports.list_bacth_on();break;
				case 'off':exports.list_bacth_off();break;
			}

		});*/
		/*新版批量操作*/
		$(".inner-container [data-act='operateAll']").on("click","a",function(e){
			var actionName=$(this).data("action");
			switch(actionName){
				case 'deleteNew':common.list_bacth_delete();break;
				case 'onNew':exports.list_bacth_on();break;
				case 'offNew':exports.list_bacth_off();break;
			}
		});
	};
	//批量上架
	exports.list_bacth_on=function(){
		var urlpathinfo = document.location.pathname.split('/');
		var url = '/' + urlpathinfo[1] + '/' + urlpathinfo[2] + '/do_onShelf';
		var __confirm = JDialog.win.work({
			title: "上架",
			width: 340,
			height: 180,
			borderWidth: 8,
			lock: true,
			effect: 0,
			content: '<div style="padding-top: 15px;">确定要批量上架这些商品吗？</div>',
			icon: 'warn',
			button: {
				'确认': function () {
					$.post(url, $("#J_List_Form").serialize(), function (data) {
						__confirm.close();
						if (data.code == "000") {
							JDialog.tip.work({type: "ok", content: data.message, timer: 1000});
							setTimeout(function () {
								location.reload();
							}, 1000)
						} else {
							JDialog.tip.work({type: "error", content: data.message, timer: __global.jdialog.timer});
						}
					}, "json");
				},
				'取消': function () {
					__confirm.close();
				}
			}

		});


	};
	//批量下架
	exports.list_bacth_off=function(){

		var urlpathinfo = document.location.pathname.split('/');
		var url = '/' + urlpathinfo[1] + '/' + urlpathinfo[2] + '/do_offShelf';
		var __confirm = JDialog.win.work({
			title: "下架",
			width: 340,
			height: 180,
			borderWidth: 8,
			lock: true,
			effect: 0,
			content: '<div style="padding-top: 15px;">确定要批量下架这些商品吗？</div>',
			icon: 'warn',
			button: {
				'确认': function () {
					$.post(url, $("#J_List_Form").serialize(), function (data) {
						__confirm.close();
						if (data.code == "000") {
							//JDialog.tip.work({type: "ok", content: data.message, timer: 1000});
							layer.alert(data.message, {time: 19000, icon:6});

							setTimeout(function () {
								location.reload();
							}, 1000)
						} else {
							//JDialog.tip.work({type: "error", content: data.message, timer: __global.jdialog.timer});
							layer.alert(data.message, {time: 19000, icon:6});

						}
					}, "json");
				},
				'取消': function () {
					__confirm.close();
				}
			}

		});

	};
});
